<?php

namespace App;

use App\Models\Cart;
use App\Models\MemberAddress;
use App\Models\MemberCoupon;
use App\Models\Order;
use App\Models\Withdrawal;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use Notifiable, HasApiTokens;

    protected $table = 'wx_members';

    protected $fillable = [
        'session_key',
        'wx_unionid',
        'wx_mini_openid',
        'wx_web_openid',
        'nickname',
        'phone',
        'avatar',
        'gender',
        'country',
        'province',
        'city',
        'gourd_coin'
    ];


    public function cart()
    {
        return $this->hasMany(Cart::class);
    }

    public function addresses()
    {
        return $this->hasMany(MemberAddress::class);
    }

    public function coupons()
    {
        return $this->hasMany(MemberCoupon::class, 'user_id', 'id');
    }

    public function orders()
    {
        return $this->hasMany(Order::class,'user_id','id');
    }

    public function withdrawal() {
        return $this->hasMany(Withdrawal::class, 'member_id', 'id');
    }
}
